package cn.cs.service;

import cn.cs.mapper.InvoiceTitleMapper;
import cn.cs.pojo.InvoiceTitle;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class RestInvoiceTitleService {


    @Resource
    private InvoiceTitleMapper invoiceTitleMapper;

    @RequestMapping(value = "/getInvoiceTitleById", method = RequestMethod.POST)
    public InvoiceTitle getInvoiceTitleById(@RequestParam("id") Long id)throws Exception{
        return invoiceTitleMapper.getInvoiceTitleById(id);
    }

    @RequestMapping(value = "/getInvoiceTitleByName", method = RequestMethod.POST)
    public InvoiceTitle	getInvoiceTitleByName(@RequestParam("name") String name, @RequestParam("userId") String userId)throws Exception{
        return invoiceTitleMapper.getInvoiceTitleByName(name, userId);
    }

    @RequestMapping(value = "/getInvoiceTitleListByUserId", method = RequestMethod.POST)
    public List<InvoiceTitle> getInvoiceTitleListByUserId(@RequestParam("userId") String userId)throws Exception{
        return invoiceTitleMapper.getInvoiceTitleListByUserId(userId);
    }

    @RequestMapping(value = "/addInvoiceTitle", method = RequestMethod.POST)
    public Integer addInvoiceTitle(@RequestBody InvoiceTitle invoiceTitle)throws Exception{
        return invoiceTitleMapper.insertInvoiceTitle(invoiceTitle);
    }

    @RequestMapping(value = "/modifyInvoiceTitle", method = RequestMethod.POST)
    public Integer modifyInvoiceTitle(@RequestBody InvoiceTitle invoiceTitle)throws Exception{
        return invoiceTitleMapper.updateInvoiceTitle(invoiceTitle);
    }

    @RequestMapping(value = "/deleteInvoiceTitleById", method = RequestMethod.POST)
    public Integer deleteInvoiceTitleById(@RequestParam("id") Long id)throws Exception{
        return invoiceTitleMapper.deleteInvoiceTitleById(id);
    }

    @RequestMapping(value = "/setDefault", method = RequestMethod.POST)
    public Integer setDefault(@RequestParam("id") Long id)throws Exception{
        return invoiceTitleMapper.setDefault(id);
    }

    @RequestMapping(value = "/setDefaultAll", method = RequestMethod.POST)
    public Integer setDefaultAll(@RequestParam("userId") String userId)throws Exception{
        return invoiceTitleMapper.setDefaultAll(userId);
    }

    @RequestMapping(value = "/getDefaultByUserId", method = RequestMethod.POST)
    public InvoiceTitle getDefaultByUserId(@RequestParam("userId") String userId)throws Exception{
        return invoiceTitleMapper.getDefaultByUserId(userId);
    }



}
